package com.zj.fx.service.month;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zj.fx.common.base.BaseService;
import com.zj.fx.common.support.ConvertUtil;
import com.zj.fx.mapper.month.MonthResultDtlMapper;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.model.month.MonthResultDtl;
import com.zj.fx.model.month.MonthResultDtlExample;
import com.zj.fx.model.month.MonthSupplytask;
import com.zj.fx.model.month.MonthSupplytaskDtl;
import com.zj.fx.shiro.util.ShiroUtils;
import com.zj.fx.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 月度结果明细表（部门审核得分明细） MonthResultDtlService
 * @Title: MonthResultDtlService.java 
 * @Package com.zj.fx.service 
 * @author SQL_自动生成
 * @email ${email}
 * @date 2023-06-26 16:20:23  
 **/
@Service
public class MonthResultDtlService implements BaseService<MonthResultDtl, MonthResultDtlExample> {
    @Autowired
    private MonthResultDtlMapper monthResultDtlMapper;

                                                                                                                            
    /**
     * 分页查询
     * @param
     * @param
     * @return
     */
    public PageInfo<MonthResultDtl> list(Tablepar tablepar,MonthResultDtl monthResultDtl) {
            MonthResultDtlExample testExample = new MonthResultDtlExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(monthResultDtl);
        }
        //表格排序
        //if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        //}else{
        //	testExample.setOrderByClause("id ASC");
        //}
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<MonthResultDtl> list = monthResultDtlMapper.selectByExample(testExample);
        PageInfo<MonthResultDtl> pageInfo = new PageInfo<MonthResultDtl>(list);
        return pageInfo;
    }
    
        @Override
        public int deleteByPrimaryKey(String ids) {
            
                List<String> lista = ConvertUtil.toListStrArray(ids);
                    MonthResultDtlExample example = new MonthResultDtlExample();
                example.createCriteria().andIdIn(lista);
                return monthResultDtlMapper.deleteByExample(example);

            
        }


        @Override
        public MonthResultDtl selectByPrimaryKey(String id) {
            
                return monthResultDtlMapper.selectByPrimaryKey(id);
            
        }


        @Override
        public int updateByPrimaryKeySelective(MonthResultDtl record) {
            return monthResultDtlMapper.updateByPrimaryKeySelective(record);
        }

    
    /**
     * 添加
     */
    @Override
    public int insertSelective(MonthResultDtl record) {
        
            //添加雪花主键id
            record.setId(SnowflakeIdWorker.getUUID());

        
        return monthResultDtlMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(MonthResultDtl record, MonthResultDtlExample example) {

        return monthResultDtlMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(MonthResultDtl record, MonthResultDtlExample example) {

        return monthResultDtlMapper.updateByExample(record, example);
    }

    @Override
    public List<MonthResultDtl> selectByExample(MonthResultDtlExample example) {

        return monthResultDtlMapper.selectByExample(example);
    }


    @Override
    public long countByExample(MonthResultDtlExample example) {

        return monthResultDtlMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(MonthResultDtlExample example) {

        return monthResultDtlMapper.deleteByExample(example);
    }

    /**
     * 审核提交时创建月度结果明细记录
     * @param monthSupplytask
     * @param id
     * @param supplytaskDtl
     */
    public void createResultDtl(MonthSupplytask monthSupplytask, String id, MonthSupplytaskDtl supplytaskDtl,String fkresultid) {
        MonthResultDtl monthResultDtl = new MonthResultDtl();
        monthResultDtl.setId(SnowflakeIdWorker.getUUID());
        monthResultDtl.setFkTaskId(id);
        monthResultDtl.setDeptId(ShiroUtils.getDepId());
        monthResultDtl.setDeptName(ShiroUtils.getDepName());
        monthResultDtl.setSupplyId(monthSupplytask.getSupplyId());
        monthResultDtl.setSupplyName(monthSupplytask.getSupplyName());
        monthResultDtl.setScore(supplytaskDtl.getSumAudit());
        monthResultDtl.setFullMark(supplytaskDtl.getSumFullMark());
        monthResultDtl.setTypeId(supplytaskDtl.getTab());
        monthResultDtl.setFkResultId(fkresultid);
        monthResultDtlMapper.insertSelective(monthResultDtl);
    }
}
